using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.Extensions.Localization {
    public class LocalizationStartup:IAgileStartup {

        public int Order => 7000;

        public void Configure(IApplicationBuilder app) {
            IList<CultureInfo> supportedCultures = new List<CultureInfo>
            {
                new CultureInfo("en-US"),
                new CultureInfo("zh-CN"),
            };
            app.UseRequestLocalization(new RequestLocalizationOptions {
                DefaultRequestCulture = new RequestCulture("zh-CN"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures
            });
        }

        public void ConfigureMvc(MvcOptions mvcOptions) {

        }

        public void ConfigureServices(IServiceCollection services,IConfiguration configuration) {
            services.AddSingleton<IStringLocalizerFactory,JsonStringLocalizerFactory>();
            services.AddSingleton<IStringLocalizer,JsonStringLocalizer>();
            services.AddLocalization(options => options.ResourcesPath = "Localization");
        }
    }
}
